package com.woniuxy.main.mycenter_ty.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.woniuxy.main.mycenter_ty.pojo.Follow;
import com.woniuxy.main.mycenter_ty.pojo.User_Ty;

public interface  MyCenterMapper {

	/**
	 * 根据手机号查详细信息
	 * @param phone
	 * @return
	 */
	@Select("select * from user where user_phone=#{phone}")
	public User_Ty queryAllInfoByPhone(String phone);   
	

	/**
	 * 自己关注别人数
	 * @param uid
	 * @return
	 */
	@Select("select count(followed_id) from follow where user_id = #{uid} and follow_state = 0 and flag =1; ") 
	public Integer myFollow(int uid);         
	
	
	/**
	 *  自己被关注数（粉丝数）
	 * @param uid
	 * @return
	 */
	@Select("select count(user_id) from follow where followed_id = #{uid} and follow_state = 0 and flag = 1;") 
	public Integer followMe(int uid);     
	
	
	/**
	 * 更新个人资料：昵称(中文名)、性别、年龄、姓名（英文）、地址、qq    
	 * 条件：手机号（唯一）
	 * @param user
	 */
	@Update("update user set user_nickname=#{user_nickname},user_sex=#{user_sex},user_age=#{user_age},user_name=#{user_name},adress=#{adress},qq=#{qq} where user_phone=#{user_phone}")
	public void updateInfo(User_Ty user);
	

	/**
	 * 查询已有粉丝信息: 粉丝（姓名、年龄、性别、电话、头像、qq、地址、关注时间、粉丝id）、本人id
	 * @param id ：本人id
	 * @return List<Follow>粉丝列表
	 */
	@Select("select user_name,user_age,user_sex,user_phone,user_headimg,"
			+ "qq,adress,create_time,u.user_id user_id, followed_id  from `user` u inner "
			+ "join follow f  on u.user_id = f.user_id where f.followed_id = #{id} "
			+ "and f.follow_state = 0 and f.flag=1;")
	public List<Follow> queryFans(int id); 


	/**
	 *  查询本人已关注的信息： 被关注者（姓名、年龄、性别、电话、头像、qq、地址、关注时间、被关注者id）、本人id
	 * @param id
	 * @return  List<Follow>：已关注列表
	 */
	@Select("select user_name,user_age,user_sex,user_phone,user_headimg,"
			+ "qq,adress,create_time,followed_id, f.user_id user_id from `user` u inner "
			+ "join follow f  on u.user_id = f.followed_id where f.user_id = #{id} "
			+ "and f.follow_state = 0 and f.flag=1 ;")
	public List<Follow> queryFollow(int id);  


	/**
	 *  关注自己的粉丝  --->变为好友
	 * @param fan
	 */
	@Update("update follow set follow_state=1 where user_id=#{user_id} and followed_id = #{followed_id} and flag=1")
	public void addFirend(Follow fan);  

	
	/**
	 * 删除某个本人已关注的用户
	 * @param fan
	 */
	@Update("update follow set flag=0 where user_id=#{user_id} and followed_id = #{followed_id}")
	public void delFollow(Follow fan);	  // 删除本人已关注


	/**
	 * 查询指定user_id 用户的详细资料
	 * @param uid
	 */
	@Select("select * from user where user_id = #{uid}")
	public User_Ty queryAllInfoByUser_id(Integer uid);

	
	/**
	 * 查询指定user_id 用户的角色
	 * @param userId
	 */
	@Select("select authentication from coach where user_id=#{userId}")
	public Integer sreachApproveState(Integer userId);

	@Update("update user set role_id=2 where user_id=#{userId}")
	public void upApproveStateState(Integer userId);
	
	@Update("update coach set authentication=2 where user_id=#{userId}")
	public void upApproveState(Integer userId);  


}
